<?php

namespace ctrl;

use model\images;
use libs\view;

class image extends base
{
	private static $M;
	public static function Init()
	{
		parent::init();
		self::$M = new images;
	}
	public static function index()
	{
		if (isset($_GET['list_json'])) {
			jsonList(self::$M->jsonPageSelect());
		} else {
			view::display();
		}
	}


	public static function add()
	{
		if (isset($_GET['view'])) {
			view::assign('image', null);
			view::assign('title', "添加图集");
			view::display("post");
		} else {
			$result = self::$M->insertData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}

	public static function edit()
	{
		if (isset($_GET['view'])) {
			$image = self::$M->findData();
			view::assign('image', $image);
			view::assign('title', "编辑图集");
			view::display("post");
		} elseif (isset($_GET['switchStatus'])) {
			if (self::$M->switchStatus())	Response(array('status' => 1, 'info' => '设置成功'));
		} else {
			$result = self::$M->updateData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}

	public static function del()
	{
		if (self::$M->deleteOneData())
			Response(array('status' => 1, 'info' => '删除成功'));
		else
			Response(array('status' => 0, 'info' => '该图集内有内容，请先删除图集内容后再删除图集！'));
	}
}
